﻿namespace Foulds.Calculator.StateMachine.Publisher
{
    /// <summary>
    /// This class is used to publish events that happens in the calculator state machine.
    /// </summary>
    public class CalculatorPublisher
    {
        #region Events
        public delegate void DisplayChange(string inputDisplay, string expressionDisplay);
        public event DisplayChange DisplayChanged;
        #endregion

        #region Properties

        #region Input Display
        /// <summary>
        /// The input display text.
        /// </summary>
        public string InputDisplay { get; protected set; }
        #endregion

        #region Expression Display
        /// <summary>
        /// The expression display text.
        /// </summary>
        public string ExpressionDisplay { get; protected set; }
        #endregion

        #endregion

        /// <summary>
        /// This method is invoked when the display state changes.
        /// </summary>
        /// <param name="inputDisplay">The text for the input display.</param>
        /// <param name="expressionDisplay">The text for the expression display.</param>
        public void OnDisplayChange(string inputDisplay, string expressionDisplay)
        {
            this.InputDisplay = inputDisplay;
            this.ExpressionDisplay = expressionDisplay;

            if (this.DisplayChanged != null)
                this.DisplayChanged(inputDisplay, expressionDisplay);
        }
    }
}
